<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitNewAftersale extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('aftersales', function (Blueprint $table) {

            $table->comment = '订单退款表';

            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->char('number', 20)->index()->comment('编号');

            $table->integer('order_id')->unsigned()->index();
            // $table->integer('tenant_id')->unsigned()->index();
            $table->integer('user_id')->unsigned()->index();

            // $table->integer('require_product_money')->nullable() ;   //退款
            // $table->integer('require_freight_fee')->nullable() ;   //退款的运费

            $table->tinyInteger('deliver_status')->unsigned()->index()->default(1)->comment('1为未收到货 2为已收到货');

            $table->string('reason', 255)->nullable()->comment('退款原因');   // 原因
            $table->text('desc')->nullable()->comment('售后说明');      // 描述
            $table->json('images')->nullable()->comment("凭证");         // 图片

            $table->json('sendback_address')->nullable()->comment('寄回地址');
            // $table->text('resend_address')->nullable();

            // $table->string('phone', 20)->nullable();

            $table->integer('refund_money')->nullable()->comment('退款人民币');         //
            $table->integer('refund_score')->nullable()->comment('退款积分'); 
            // $table->string('refund_number', 100)->nullable();         // 凭证

            $table->json('audit_remark')->nullable()->comment('审核留言'); // 审核留言

            $table->json('sendback_info')->nullable()->comment('寄回物流信息');   // 退回快递
            $table->json('resend_info')->nullable()->comment('重新寄物流信息');   // 重新发出快递

            $table->timestamp('audited_at')->nullable()->comment('审核时间');    // 审核于
            $table->timestamp('sendback_recevied_at')->nullable()->comment('寄回收货时间');   // 接收于
            $table->timestamp('sendback_at')->nullable()->nullable()->comment('寄回时间');   // 寄回于
            $table->timestamp('resend_at')->nullable()->comment('重寄时间');     // 重新寄出
            $table->timestamp('resend_recevied_at')->nullable()->comment('重寄收货时间');   // 接收于
            $table->timestamp('refunded_at')->nullable()->comment('退款时间');   // 接收于
            $table->timestamp('completed_at')->nullable()->comment('完成时间');   // 完成于

            $table->tinyInteger('status')->default(1)->comment('0为拒绝申请  1为申请中   2为流程中   3为已完成    4为已中止取消'); // 0为拒绝申请  1为申请中   2为流程中   3为已完成    4为已中止取消

            $table->tinyInteger('sub_status')->default(0)->comment('0为无操作  1为买家已退回  2为卖家已收货 3为卖家已经寄出  4为卖家已退款  5为买家已重新收货'); // 0为无操作  1为买家已退回  2为卖家已收货 3为卖家已经寄出  4为卖家已退款  5为买家已重新收货

            $table->softDeletes();
            $table->timestamps();

            $table->foreign('order_id')->references('id')->on('orders')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('aftersales');
    }
}
